import { sickbed_approval } from '@/services/sickbeds';
import { ActionType, ProForm, ProFormTextArea } from '@ant-design/pro-components';
import { Divider, Modal, message } from 'antd'
import React from 'react'
interface Iprops {
    isShowAgreeModal: (show: boolean) => void;
    isAgreeModalOpen: boolean;
    id: number | undefined;
    actionRef: React.MutableRefObject<ActionType | undefined>;
}
const Agree = (props: Iprops) => {
    const { isAgreeModalOpen, isShowAgreeModal, id, actionRef } = props

    // 点击取消的回调
    const onReset = () => {
        isShowAgreeModal(false);
    };

    // 审批同意
    const ConfirmAgree = async (values: any) => {
        console.log('values', values);
        let res: any = await sickbed_approval({ id, ...values, status: 1 })
        if (res.code == 200) {
            // 刷新列表
            actionRef.current?.reload();
            message.success('审批同意成功');
            // 关闭弹窗
            isShowAgreeModal(false)
        } else {
            message.error(res.msg)
        }
    }
    return (
        <Modal
            title="同意建床"
            centered
            open={isAgreeModalOpen}
            onCancel={() => isShowAgreeModal(false)}
            destroyOnClose={true}
            width={400}
            footer={null}
        >
            <Divider />
            <ProForm
                layout='horizontal'
                onReset={() => onReset()}
                onFinish={async (values) => ConfirmAgree(values)}
                submitter={{
                    // 配置按钮文本
                    searchConfig: {
                        resetText: '取消',
                        submitText: '提交',
                    },
                    resetButtonProps: {
                        style: {
                            // 隐藏重置按钮
                            display: 'block',
                            position: 'absolute',
                            left: 'calc(50% - 107px)',
                        },
                    },
                    submitButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            right: 'calc(50% - 107px)',
                        },
                    },
                }}
            >
                <ProFormTextArea
                    name="reason"
                    label="同意原因:"
                    placeholder="请填写同意原因!"
                    rules={[
                        {
                            max: 100,
                            message: '字数最多100个字符',
                        },
                    ]}
                />
                <br />
            </ProForm>
            <br />
        </Modal>
    )
}
export default Agree